<?php
$_GET['key']=($_GET['key']=="")?"中国女队游泳":$_GET['key'];
$key=urlencode($_GET['key']);
$key=$_GET['key'];
$s_url="http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1471418062066_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word={$key}&f=3&oq={$key}&rsp=0";
$url="http://collect.longsunhd.com/collect/index.php?gather_type=1&bug=1&s_url=".urlencode($s_url);
//$data=json_decode(file_get_contents($url),1);
$data=json_decode(curlbase($url),1);
preg_match_all("/\[img\](?:[^\]\[]*url=)?(.*)\[\/img\]/Uisx",$data['message'],$nn);
$arr=array();
for($i=0;$i<count($nn[1]);$i++){
    $arr[]=urldecode($nn[1][$i]);
}
echo json_encode($arr);



function curlbase($url,$Querystring="",$cookie2="",$Referer="",$header=0,$proxy=""){
    static $cookie;
    $host=whost($url);
    $durl=$url;
    $Referer=($Referer=="")?"http://{$host}/":$Referer;
    $timeout=5;
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //curl_setopt($ci, CURLOPT_PROXY, '192.168.1.130:8080');//自己设置的代理，
    //curl_setopt($ci, CURLOPT_PROXYUSERPWD, 'username:pwd');//公司上网的账号密码，
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    /*if(preg_match("/multipart/Uisx",$post)){
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    }*/
    if($Referer!=""){
        curl_setopt($ch, CURLOPT_REFERER, $Referer);
    }
    if($cookie2!=""){
        curl_setopt($ch, CURLOPT_COOKIE, $cookie2);
    }
    if($Querystring!=""){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
    }
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLINFO_HEADER_OUT, $header);
    $r = curl_exec($ch);
    curl_getinfo( $ch, CURLINFO_HEADER_OUT);
    curl_close($ch);
    $GLOBALS['returncookie']=$cookie=getcookies($r,$cookie2);
    if (preg_match("/Location:\s*([^\r\n]+)/isx", $r, $nn)) {
        $GLOBALS['jumpurl']="";
        if($url!=trim($nn[1])&&$oldurl!=$url) {
            $oldurl=$url;
            $durl = quanurl(trim($nn[1]),$oldurl);
            $GLOBALS['jumpurl']=$url;
            $r = curlbase($durl,"", $cookie, $Referer,$header,$proxy);
        }
    }

    if (preg_match("/self\.location=[\"']([^<>\"\']*)[\"']/Uisx", $r, $nn)) {
        $GLOBALS['jumpurl']="";
        $nn[1]=quanurl($nn[1],$durl);
        if($durl!=trim($nn[1])||$oldurl!=$durl||$cookie!=$oldcookie) {
            $oldurl=$durl;
            $oldcookie=$cookie;
            $zz=parse_url($durl);
            $durl = quanurl(trim($nn[1]), "http://".$zz[host]."/");
            $r = curlbase($durl,"", $cookie, $Referer,1,$proxy);
            $GLOBALS['jumpurl']=$durl;
        }
    }
    if(preg_match("/^http\/(.*)(?:\r\n\r\n|\n\n)(.+?)$/Uis", $r, $nn)){
        $body = $nn[2];
        if (!preg_match("/html|img/Uisx",$r)&&@gzinflate(substr($body, 10))) {
            $body = gzinflate(substr($body, 10));
        }
    }else{
        $body=$r;
    }
    if($header){
        $result=$nn[1]."\r\n\r\n".$body;
    }else{
        $result=$body;
    }
    return $result;
}

function quanurl($subUrl, $wurl, $baseurl = "")
{
    if (is_array($subUrl) || $subUrl == "") return "";
    $baseurl = preg_replace("/(http\:\/\/[^\/]+)$/Uisx", "\\1/", $baseurl);
    $subUrl = str_replace('\\', "/", $subUrl);
    $subUrl = str_replace('&', "&", $subUrl);
    $subUrl = preg_replace("/^\.\?/", "?", $subUrl);
    $wurl = ($baseurl) ? $baseurl : $wurl;
    $wurl = preg_replace("/\?.*$/Uisx", "", $wurl);
    preg_match_all("/(http\s?\:\/\/([^\/]*?))(.*)$/Uimx", $wurl, $mm);
    $host = $mm[2][0];
    $subUrl = preg_replace("/^\/\//", "http://", $subUrl);
    if (substr($subUrl, 0, 7) == "http://" || substr($subUrl, 0, 8) == "https://") {
        $newurl = $subUrl;
    } elseif (preg_match("/^\//", $subUrl)) {
        $newurl = "http://" . $host . $subUrl;
    } elseif (preg_match("/^\.\.\//", $subUrl)) {
        $tmsuburl = $subUrl;
        $tempparentUrl = $wurl;
        preg_match_all("/(\.\.\/)/Uisx", $subUrl, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $tmsuburl = preg_replace("/^\.\.\//", "", $tmsuburl);
            $tempparentUrl = preg_replace("/(?!<\/)\/[^<>\/]*\/[^<>\/]*$/", "/", $tempparentUrl);
        }
        $newurl = preg_replace("/\/$/", "", $tempparentUrl) . "/" . $tmsuburl;
    } elseif (preg_match("/^[^\.\/\?]/", $subUrl)) {
        preg_match("/^(.*)\//Uisx", $subUrl, $nna);
        preg_match("/http\:\/\/.*\/(.*)\//Uisx", $wurl, $nnb);
        if ($nnb[1] == $nna[1]) {
            $newurl = "http://" . $host . "/" . $subUrl;
        } else {
            $newurl = $this->dirname2($wurl) . "/" . $subUrl;
        }
    } elseif (preg_match("/^\?/", $subUrl)) {
        $newurl = preg_replace("/\?.*$/U", "", $wurl) . $subUrl;
    } else {
        $newurl = preg_replace("/\/[^\/]*$/", "/", $wurl) . $subUrl;
    }
    $newurl = preg_replace("/\/\.\//", "/", $newurl);
    $newurl = preg_replace("/\/http\:\//", "/", $newurl);
    return $newurl;
}

function dquanurl($nr, $wurl, $baseurl)
{
    $nr = preg_replace_callback("/(src|location|<link[^>]*href|<EMBED[^>]*VALUE|action|background|imgurl|<PARAM\s+NAME\=movie\s+VALUE|href)\s*=\s*(\" | \')?([^\"\'\>\s]+)(\\2|(?=\>)|\s)/Uisx", function($em) use($wurl,$baseurl){
        return "{$em[1]} = \"".$this->quanurl("{$em[1]}",$wurl,$baseurl)."\"";
    }, $nr);
    $nr = preg_replace_callback("/url\((\"|' |)?([^<>\s\"']+)\\1\)/Uisx", function($em) use($wurl){
        return "url(".$this->quanurl($em[2],$wurl).")";
    }, $nr);
    return $nr;
}

function dirname2($wurl)
{
    if (substr($wurl, -1, 1) == "/") {
        return substr($wurl, 0, -1);
    } else {
        return dirname($wurl);
    }
}

function getCookie($nr){
    preg_match("/setCookie\:\s*([^<>]+)$/",$nr,$nn);
    return $nn[1];
}


function getCookies($nr,$cookie){
    preg_match_all("/Set-Cookie\:\s+(.*)(?:$|(?:path|domain|expires)\s*=)/Uimx",$nr,$nn);
    $cstr="$cookie";
    for($i=0;$i<count($nn[1]);$i++){
        $cstr.=";".trim($nn[1][$i]);
    }

    preg_match_all("/document\.cookie=['\"]([^<>]*)['\"]/Uimx",$nr,$nn);
    for($i=0;$i<count($nn[1]);$i++){
        $cstr.=";".trim($nn[1][$i]);
    }


    $str=preg_replace("/\;+/",";",$cstr);
    $str=preg_replace("/^\;/","",$str);
    $nn=explode(";",$str);
    $arr=array();
    $arr2=array();
    foreach($nn as $k=>$v){
        $ar=explode("=",$v);
        if(trim($ar[0])!=""){
            $arr2[trim($ar[0])]=trim($ar[1]);
        }
    }
    $s="";
    foreach($arr2 as $k=>$v){
        $s.=$k."=".$v.";";
    }
    return $s;
}
function whost($str)
{
    preg_match_all("/http\:\/\/([^\/]+)/", $str, $nn);
    $whost = $nn[1][0];
    return $whost;
}

function host($str)
{
    $str=($str=="")?$this->url:$str;
    preg_match_all("/http\:\/\/(?:[^<>\.]+\.)??([^<>\/]+(?<!www)(\.(com|gov|edu|org)(?=\/|$|\.cn)|\.cn(?=\/|$|\:)|\.net|\.cc|\.tv|\.hk|\.tw)+?)/Uisx", $str, $nn);
    $host = $nn[1][0];
    $host = preg_replace("/^(?:[^<>]*\.)*([a-z0-9_]+\.(com|gov|edu|org|cn))/Uisx", "\\1", $host);
    if($str=="") $this->host=$host;
    return $host;
}

